<template>
	<view style="background-color: #fff;height: 100%;">
		<view>
			<uni-nav-bar fixed="true" :left-icon="isToken?'back':''" :status-bar="true" :border="false" title="登录"
				class="NavBar" @clickLeft="NavBar()">
				<view slot="right" @click="cut()"></view>
			</uni-nav-bar>
		</view>

		<view class="authorized" v-if="(WeiXin&&grant) || (isWeiXin()&&grant)">
			<!-- <image class="authorized-logo" :src="`${picUrl}/jh/login_logo.png`" mode="aspectFit"></image> -->
			<image class="authorized-logo" :src="physicalInfo.logo" mode="aspectFit"></image>
			<view class="authorized-logoText"></view>
			<!-- <button class='authorized-btn authorized-wxbtn' open-type="getUserProfile"
				@click.stop="WXlogin">授权登录</button> -->
			<button class='authorized-btn authorized-zhbtn' @click="login()">手机号登录</button>
		</view>
		
		<view class="automatic_logon" v-if="(WeiXin&&grant) || (isWeiXin()&&grant)" style="margin-left: 20px;">
		
			<view class="chenkeduser_box_pent">
				<view>
					<checkbox-group @change="checkboxChangeifchen">
						<label>
							<checkbox color="#ff4300" :checked="ifchenked" style="transform:scale(0.7)"
								value='ifchenked' />
						</label>
					</checkbox-group>
				</view>
				<view style="margin-left: -22rpx; line-height: 0;">
					请勾选并同意 <text style="color: #FF4300;" @click="Agreement(0)">《隐私协议》</text>和<text
						style="color: #FF4300;" @click="Agreement(1)">《服务协议》</text>
				</view>
			</view>
		</view>
		

		<view class="bgco shadow" v-if="isbinding">
			<view class="previous" @click="Toindex()">
				<image :src="`${picUrl}/w/cha2.png`" mode=""></image>
			</view>
			<view class="Box">
				<view class="ImgBox">
					<image :src="avatarUrl" mode=""></image>
				</view>
				<!-- <view class="">{{titleText?"请输入注册手机号":"请输入绑定手机号"}}</view> -->
				<view class="flexBox mag40"><text>手机号：</text><input class="Phone" type="number" v-model="username"
						:placeholder="titleText?'请输入注册手机号':'请输入绑定手机号'" maxlength="11" style="text-align: left;" />
				</view>
				<view class="flexBox mag40" style="border-bottom: 1rpx solid #eee;height: 50rpx;">
					<text>验证码：</text><input type="number" v-model="vercode" value="" maxlength="6"
						placeholder="请输入验证码" />
					<view class="phone_code" :class="{'getactive':iscode}" @click="phone_code">
						{{getCode}}
					</view>
				</view>
				<button class='authorization' @click="binding()" style="margin-top: 80rpx;">确认绑定</button>
			</view>
		</view>

		<view class="login_content ZH-login">
			<!-- #ifdef APP-PLUS -->
			<view v-if="(!WeiXin&&!isWeiXin()&&!ishide&&!isbinding) || !grant" style="height: 150rpx;"></view>
			<!-- #endif -->
			<view v-if="(!WeiXin&&!isWeiXin()&&!ishide&&!isbinding) || !grant">
				<!-- <image class="ZH-logo" :src="`${picUrl}/jh/login_logo.png`" mode="aspectFit"></image> -->
				<image class="ZH-logo" :src="physicalInfo.logo" mode="aspectFit"></image>
				<view class="userlogin_box" style="width: 650rpx;">
					<view v-if="!loginfun">
						<view class="item flex1">
							<view class="login_left_icon flex0">
								<image src="../../static/images/login/shouji-icon.png" mode="aspectFit"></image>
								<input type="number" maxlength="11" v-model="username" v-on:input="usernameinput"
									placeholder="请输入手机号码" class="login_input" />
							</view>
							<view style="height:36rpx;" class="login_icon">
								<image class="cloer_icon" v-if="cloershow" src="../../static/images/cloer.png" mode=""
									@click="cloerUser"></image>
							</view>
						</view>
						<view class="item flex1" style="margin-top: 50rpx;">
							<view class="login_left_icon flex0">
								<image src="../../static/images/login/anquan-icon.png" mode="aspectFit"></image>
								<input type="number" maxlength="6" class="login_input" style="width: 400rpx;"
									v-model="userpass2" placeholder="请输入验证码" />
							</view>
							<view class="obtain_code" :class="{'getactive':iscode}" @click="phone_code">
								{{getCode}}
							</view>
						</view>
					</view>
					<view v-if="loginfun==1">
						<view class="item flex1">
							<view class="login_left_icon flex0">
								<image src="../../static/images/login/shouji-icon.png" mode="aspectFit"></image>
								<input type="text" class="login_input" v-model="username" v-on:input="usernameinput"
									placeholder="请输入手机号" />
							</view>
							<view style="height:36rpx;" class="login_icon">
								<image class="cloer_icon" v-if="cloershow" src="../../static/images/cloer.png" mode=""
									@click="cloerUser"></image>
							</view>
						</view>
						<view class="item flex1" style="margin-top: 50rpx;">
							<view class="login_left_icon flex0">
								<image src="../../static/images/login/suo-icon.png" mode="aspectFit"></image>
								<input type="password" class="login_input" v-if="!isSee" v-model="userpass"
									placeholder="请输入密码" />
								<input type="text" class="login_input" v-else v-model="userpass" placeholder="请输入密码" />

							</view>
							<view class="" @click="seeWord">
								<image v-if="!isSee" style="width: 40rpx; height: 13rpx;padding-top: 10rpx;"
									src="../../static/images/see_icon.png" mode="aspectFit">
								</image>
								<image v-if="isSee" style="width: 40rpx; height: 30rpx;padding-top: 15rpx;"
									src="../../static/images/see.png" mode="aspectFit"></image>
							</view>
						</view>
					</view>
					
					<view v-if="loginfun==2">
						<view class="item flex1">
							<view class="login_left_icon flex0">
								<image src="../../static/images/login/shouji-icon.png" mode="aspectFit"></image>
								<input type="text" class="login_input" v-model="username" v-on:input="usernameinput"
									placeholder="请输入账号" />
							</view>
							<view style="height:36rpx;" class="login_icon">
								<image class="cloer_icon" v-if="cloershow" src="../../static/images/cloer.png" mode=""
									@click="cloerUser"></image>
							</view>
						</view>
						<view class="item flex1" style="margin-top: 50rpx;">
							<view class="login_left_icon flex0">
								<image src="../../static/images/login/suo-icon.png" mode="aspectFit"></image>
								<input type="password" class="login_input" v-if="!isSee" v-model="userpass"
									placeholder="请输入密码" />
								<input type="text" class="login_input" v-else v-model="userpass" placeholder="请输入密码" />
					
							</view>
							<view class="" @click="seeWord">
								<image v-if="!isSee" style="width: 40rpx; height: 13rpx;padding-top: 10rpx;"
									src="../../static/images/see_icon.png" mode="aspectFit">
								</image>
								<image v-if="isSee" style="width: 40rpx; height: 30rpx;padding-top: 15rpx;"
									src="../../static/images/see.png" mode="aspectFit"></image>
							</view>
						</view>
					</view>

					<view class="automatic_logon">

						<view class="chenkeduser_box_pent">
							<view>
								<checkbox-group @change="checkboxChangeifchen">
									<label>
										<checkbox color="#ff4300" :checked="ifchenked" style="transform:scale(0.7)"
											value='ifchenked' />
									</label>
								</checkbox-group>
							</view>
							<view style="margin-left: -22rpx; line-height: 0;">
								请勾选并同意 <text style="color: #FF4300;" @click="Agreement(0)">《隐私协议》</text>和<text
									style="color: #FF4300;" @click="Agreement(1)">《服务协议》</text>
							</view>
						</view>
						<view @click="toforgetpwd()" class="automatic_logon_right"
							style="text-align: right;margin-top: 20rpx;">
							<text>忘记密码?</text>
						</view>
					</view>

					<view class="userlogin_submit" @click="userLogin">
						登录
					</view>
					<view class=" switch">
						<view @click="change()" style="font-size: 28rpx;">
							{{loginfun?"短信登录":"密码登录"}}
						</view>
						<view @click="accout()" style="font-size: 28rpx;">
							账号登录
						</view>
						<!-- <view style="width: 1rpx; height: 30rpx; background: #C5C5C5;"></view>
						<navigator url="register" class="switch-register">
							新用户注册
						</navigator> -->
					</view>
					<view class="third_party_login" v-if="isApp">
						<view class="line">
						</view>
						<view class="third_party_login_text">
							第 三 方 登 录
						</view>
						<view class="line">
						</view>
					</view>
					<view class="third_party_login_icon" v-if="isApp">
						<image v-if="WeiXinapp" @click="loginuni" src="../../static/images/wxicon.png" mode=""></image>
						<!-- <image v-if="qqapp" @click="loginqq" src="../../static/images/qqiocn.png" mode=""></image> -->
						<image @click="loginAlipay" src="../../static/images/payment/alipay.png" mode=""></image>
					</view>
				</view>
			</view>

		</view>

		<uni-popup ref="Privacy" type="center">
			<view class="frameBox">
				<scroll-view class="scroll-view" scroll-y="true" style="height: 800rpx;">
					<view v-html="frame"></view>
				</scroll-view>
			</view>
		</uni-popup>
		<!-- #ifdef MP-WEIXIN -->
		<uni-popup type="bottom" ref="getnickshow" @close="close">
			<view class="getnickbox">
				<view class="flex_align_center">
					<image :src="project.logo" class="logoimg" mode="aspectFit"></image>
					<view class="name">
						{{project.name}}
						<text>申请</text>
					</view>
				</view>
				<view class="m1 mt30">获取你的头像、昵称</view>
				<view class="m2">展示个人信息</view>
				<view class="xin1">
					<button type="default" class="flex_spacebetween buttoncss" open-type="chooseAvatar"
						@chooseavatar="chooseavatar">
						<view class="flex_align_center toubox">
							<view class="t1">头像</view>
							<view v-if="avatarUrl == ''" class="avatarbox">
								<u-icon name="account-fill" size="50" color="#999"></u-icon>
							</view>
							<image v-else :src="avatarUrl" class="avatarimg"></image>
						</view>
						<image src="../../static/images/right_arrow.png" class="right_arrow"></image>
					</button>
				</view>
				<view class="nick">
					<view class="n1">昵称:</view>
					<input type="nickname" v-model="nickname" @change="watchNick" placeholder="请输入昵称">
				</view>
				<view class="fixedBtn wan">
					<button open-type="getUserInfo" @click="getUserInfo" class="authorized-btn btn">完成</button>
				</view>
			</view>
		</uni-popup>
		<view class="logobox" v-if="phoneAuthPopup">
			<view class="logoboxcenter">
				<view class="logoboxtitle">
					为了更好的用户体验，需要你授权手机号
				</view>
				<view class="">
					<button class="register" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
						去授权
					</button>
				</view>
			</view>
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	// #ifdef APP-PLUS
	const AlipayAuth = uni.requireNativePlugin("DHQ-AlipayAuth")
	// #endif
	const requImg = require("@/common/api_sign/requImg.js")
	import server from '@/common/api_sign/request.js'
	const util = require("../../common/api_sign/request.js")
	const msdjs = require('../../common/api_sign/md5.js');
	import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue'
	import uniPopup from "@/components/uni-popup/uni-popup.vue"
	export default {
		data() {
			return {
				project: {
					name: '',
					logo: '',
				},
				physicalInfo:{},
				phoneAuthPopup: false,
				from: "",
				// 控制类
				isSee: false,
				cloershow: false,
				username: "",
				userpass: "",
				userpass2: "",
				vercode: "",
				isshowChenk: false,
				ifchenked: false,
				getCode: "获取验证码",
				iscode: true,
				server: server,
				time: 60,
				beforePage: '',
				client: "wap",
				isApp: false,
				WeiXin: false,
				code: "",
				isbinding: false,
				titleText: false,
				unionId: "",
				openId: "",
				types: "wx",
				headimgurl: "",
				qqopenid: "",
				ishide: false,
				invitation: "", //邀请码
				loginfun: 1,
				WeiXinapp: true,
				qqapp: true,
				frame: "",
				grant: true,
				previous: "",
				isToken: true,

				nickname: "",
				avatarUrl: '',
				wxCallbackUserInfo:null //微信授权，只要一次就行 解决登录报失败，因为重复使用登录code
			}
		},
		onShow() {
			// 获取项目的 logo 和 名称
			// #ifdef MP-WEIXIN
			uni.getSystemInfo({
				success: (res) => {
					this.project.name = res.appName
				}
			})
			this.project.logo = __wxConfig.accountInfo.icon

			uni.login({
				provider: 'weixin',
				success: (loginRes) => {
					this.code = loginRes.code
					console.log('login', this.code)
				}
			})

			// #endif
		},
		onLoad(e) {
			this.getPhyInfo()
			if (uni.getStorageSync("InvitationCode")) {
				this.invitation = uni.getStorageSync("InvitationCode")
			}

			let pages = getCurrentPages(); // 当前页面
			if (pages.length > 1) {
				this.beforePage = pages[pages.length - 2].route; // 前一页面	
			}

			// #ifdef H5
			let ua = window.navigator.userAgent.toLowerCase();
			if (ua.match(/MicroMessenger/i) == 'micromessenger') {
				this.client = "wechat"
				this.beforePage = encodeURIComponent(e.href)
				let url = this.$share + "/#/mainA/login/login?previous=" + this.beforePage

				url = encodeURIComponent(url)
				// console.log('测试',url)
				let wx_url = this.$wxOfficialAccountUrl + "&redirect_uri=" + url +
					"&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";
				// 获取URL上code
				this.code = this.getUrlParam('code')
				this.previous = this.getUrlParam('previous')
				0 // 判断是否存在code
				if (this.code == null || this.code == '') {
					uni.setStorageSync("previous", e.href)
					window.location.href = wx_url
				}

			} else {
				this.client = "wap"
			}
			// #endif
			this.from = uni.getStorageSync('pageFrom') || "other"
			// #ifdef APP-PLUS
			this.isApp = true;
			if (plus.runtime.isApplicationExist({
					pname: 'com.tencent.mm',
					action: 'weixin://'
				})) {
				this.WeiXinapp = true
				console.log("微信应用已安装");
			} else {
				this.WeiXinapp = false
				console.log("微信应用未安装");
			}
			if (plus.runtime.isApplicationExist({
					pname: 'com.tencent.mobileqq',
					action: 'mqq://'
				})) {
				this.qqapp = true
			} else {
				this.qqapp = false
			}
			switch (uni.getSystemInfoSync().platform) {
				case 'android':
					this.client = "android"
					break;
				case 'ios':
					this.client = "ios"
					break;
			}
			// #endif

			// #ifdef MP-WEIXIN
			this.WeiXin = true
			this.client = "applet"
			// this.firstLogin()
			// #endif
		},

		methods: {
			// 获取logo
			getPhyInfo(){
				let that = this
				that.$util.request({
					url: '/mobile/index.php?act=index&op=getPhyInfo',
					method: 'POST',
					data: {
					  source:"41",
					},
				}).then((res) => {
					console.log(res,'res11');
					this.physicalInfo = res.datas;
					uni.setStorageSync("physicalInfo", res.datas);
				})
			
			},
			watchNick(e) {
				this.nickname = e.detail.value
			},
			login() {
				this.grant = false
			},
			Agreement(index) { //隐私协议
				// let url = ""
				let did = ""
				if (index == 0) {
					// url = '/mobile/index.php?act=document&op=privacy_doc'
					did = '418'
				} else {
					// url = '/mobile/index.php?act=document&op=user_doc'
					did = '411'
				}
				util.request({
					// url: url,
					url: '/mobile/index.php?act=document&op=index',
					method: 'get',
					data: {
					  did:did,
					},
				}).then((res) => {
					this.frame = res.datas.content
				})
				this.$refs.Privacy.open()
			},
			// 取消
			Toindex() {
				this.isbinding = false
				this.ishide = false
			},
			change() {
				this.loginfun = !this.loginfun
				this.userpass = ""
				this.userpass2 = ""
			},
			accout(){
				this.loginfun = 2
				this.userpass = ""
				this.userpass2 = ""
			},
			phone_code() {
				// 发送状态
				let that = this;
				if (that.username) {
					if (that.iscode) {
						that.iscode = false;
						this.$util.request({ //绑定账号获取验证码
							url: '/mobile/index.php?act=login&op=sendCode',
							method: 'post',
							data: {
								"actiontype": this.titleText ? 0 : 1,
								"mobile": that.username,
							},
						}).then(function(res) {
							if (res.error_code == 0) {
								let codesetInterval = setInterval(() => {
									that.time--;
									that.getCode = that.time + "s"
									if (that.time <= 0) {
										clearInterval(codesetInterval);
										that.getCode = "获取验证码";
										that.iscode = true;
										that.time = 60;
									}
								}, 1000)
							} else {
								uni.showToast({
									title: res.message,
									icon: "none"
								})
								that.iscode = true;
							}
						})
					}
				} else {
					uni.showToast({
						title: "手机号不能为空",
						icon: "none"
					})
				}
			},

			getUrlParam(name) { //公众号截取code
				let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
				let r = window.location.search.substr(1).match(reg)
				if (r != null) {
					return unescape(r[2])
				}
				return null
			},
			// #ifdef H5
			WXlogin(e) { //公众号登录
				uni.showLoading({})
				let that = this
				if (this.isWeiXin()) {
					util.request({
						url: '/mobile/index.php?act=login&op=wx_oauth',
						method: 'POST',
						data: {
							code: that.code,
							client: that.client,
						},
					}).then((res) => {
						uni.hideLoading()
						if (res.error_code != 0) {
							uni.showToast({
								title: res.message,
								icon: "none"
							})
							return false
						}

						if (res.datas.state == 1) {
							// 存下缓存
							that.huancun(res);
						} else {
							uni.showModal({
								title: '提示',
								content: '是否注册新账号?',
								cancelText: "已有账号", //取消按钮文字
								confirmText: "新用户", //确认按钮文字
								success: function(res2) {
									if (res2.confirm) {
										if (res.datas.share_id) {
											that.invitation = res.datas.share_id;
										}
										that.titleText = true
										that.isbinding = true;
									} else if (res2.cancel) {
										that.titleText = false
										that.isbinding = true;
									}
								}
							});
							console.log(res.datas.wx_userinfo, 7777)
							that.unionId = res.datas.wx_userinfo.unionid;
							that.openId = res.datas.wx_userinfo.openId;
						}
					})
				}
			},
			// #endif
			// #ifdef MP-WEIXIN
			WXlogin() { //小程序登录
			    if (!this.ifchenked) {
					uni.showToast({
						title: "请同意隐私协议",
						icon: "none"
					})
					return;
				} 
				let that = this
				
				if (this.wxCallbackUserInfo != null) {
					let res = that.wxCallbackUserInfo
					if (res.datas.state == 1) {
						that.huancun(res)
					} else {
						that.openId = res.datas.openid
						that.unionId = res.datas.unionid
						that.$refs.getnickshow.open()
					}
					return;
				}
				

				if (this.code.length == 0) {
					uni.showLoading({
						mask:true
					})
					
					uni.login({
						provider: 'weixin',
						success: (loginRes) => {
							this.code = loginRes.code
							console.log('login', this.code)
							uni.hideLoading()
							this.WXlogin()
						}
					})
					return;
				} 

				uni.getUserProfile({
					desc: '用于完善资料和登录',
					success: (data) => {
						console.log(data)
						
						uni.showLoading({
							mask:true
						})

						if (data.encryptedData) {
							that.$util.request({
								url: '/mobile/index.php?act=login&op=applet_oauth',
								method: 'POST',
								data: {
									code: that.code,
									iv: data.iv.replace(/\=/g, "%3D"),
									encryptedData: data.encryptedData.replace(
										/\=/g, "%3D")
								},
							}).then(res => {
								uni.hideLoading()
								if (res.error_code == 0) {
									that.wxCallbackUserInfo = res
									if (res.datas.state == 1) {
										that.huancun(res)
									} else {
										that.openId = res.datas.openid
										that.unionId = res.datas.unionid
										that.$refs.getnickshow.open()
									}
								} else {
									uni.showToast({
										title: res.message,
										icon: 'none'
									});
								}
							}).catch(e=>{
								uni.hideLoading()
							})
						}else {
							uni.hideLoading()
						}
					},
					fail: (res) => {
						console.log(res)
						uni.hideLoading()
					}
				});
			},
			// 选择用户头像，重点，得调用下上传图片接口
			chooseavatar(e) {
				let data = requImg.request("index.php?act=upload&op=uploadFile&buss_type=" + this.$uploadType
					.uploadtype002);
				uni.uploadFile({
					url: this.$apiurl + 'index.php?act=upload&op=uploadFile',
					filePath: e.detail.avatarUrl,
					name: 'file',
					formData: {
						key: data.key,
						buss_type: data.buss_type,
						api_sign: data.api_sign,
						comefrom: data.comefrom,
						api_time: data.api_time,
					},
					success: r => {
						let imgData = JSON.parse(r.data)
						console.log(imgData)
						this.avatarUrl = imgData.datas.file_url
					}
				});
			},
			getUserInfo() {
				if (this.avatar == "") {
					uni.showToast({
						title: '请上传头像',
						icon: 'none'
					})
					return
				}
				if (this.nickname == "") {
					uni.showToast({
						title: '请编辑用户昵称或昵称不能使用特殊字符',
						icon: 'none'
					})
					return
				}
				this.$refs.getnickshow.close()
				this.phoneAuthPopup = true
			},
			getPhoneNumber(e) {
				this.phoneAuthPopup = false
				// 用户拒绝授权
				if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
					wx.showToast({
						icon: "none",
						title: '请允许获取手机号，否则功能不可用！',
					})
					return
				}
				let that = this
				that.$util.request({
					url: '/mobile/index.php?act=login&op=oauth_register',
					method: 'POST',
					data: {
						openid: that.openId,
						unionid: that.unionId,
						avatar: that.avatarUrl,
						nickname: that.nickname
					},
				}).then((res) => {
					if (res.error_code != 0) {
						uni.showToast({
							title: res.message,
							icon: "none"
						})
						return false
					}
					if (res.datas.state == 1) {
						// 存下缓存
						that.huancun(res)
					}
				})
			},
			firstLogin() {
				uni.login({
					provider: 'weixin',
					success: (res) => {
						console.log('首次调用', res.code)
					},
					fail: () => {
						uni.showToast({
							title: "微信登录授权失败",
							icon: "none"
						});
					}
				})
			},
			// #endif
			binding() { //绑定或注册
				let that = this
				let url = ""
				if (this.titleText) {
					url = '/mobile/index.php?act=login&op=bind_register'
				} else {
					url = '/mobile/index.php?act=login&op=bind_register'
				}
				if (that.username && that.vercode) {
					console.log(that.unionid, 'unionidunionidunionidunionid')
					console.log(that.openId, 'openidopenidopenidopenid')
					util.request({
						url: url,
						method: 'POST',
						data: {
							username: that.username || "",
							vercode: that.vercode || "",
							type: that.types || "",
							nickname: that.nickname || "",
							headimgurl: that.headimgurl || "",
							qqopenid: that.qqopenid || "",
							share_id: that.invitation || "",
							openid: that.openId || "",
							unionid: that.unionId || "",
						},
					}).then((res) => {
						// 存下缓存
						this.huancun(res);
					})
				} else {
					uni.showToast({
						title: "手机号验证码不能为空",
						icon: "none"
					})
				}

			},
			//是否是微信内置浏览器
			isWeiXin() {
				// #ifdef H5
				let ua = window.navigator.userAgent.toLowerCase();
				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
					return true;
				} else {
					return false;
				}
				// #endif
			},
			NavBar() {
				uni.reLaunch({
					url: "/main/home/index"
				});
			},
			userLogin() { //账号密码登录
				if (!this.ifchenked) {
					uni.showToast({
						title: "请同意隐私协议",
						icon: "none"
					})
					return false
				}
				uni.showLoading({})
				let that = this;
				// let iv=""
				// let encryptedData=""
				let applet = 0
				if ((that.username && that.userpass) || (that.username && that.userpass2)) {
					// #ifdef MP-WEIXIN
					applet = 1
					let loginType="";
					if(!that.loginfun){
						loginType='isMobile';
					}else{
						if(that.loginfun==1){
							loginType='isAccount';
						}else{
							loginType='isNickname';
						}
					}
					uni.login({
						provider: 'weixin',
						success: function(loginRes) {
							that.code = loginRes.code
							util.request({
								url: '/mobile/index.php?act=login&op=loginThreeWay',
								method: 'POST',
								data: {
									username: that.username,
									password: msdjs.hexMD5(that.userpass),
									vercode: that.userpass2,
									client: that.client,
									login_role: "1",
									loginType: loginType,
									wxcode: that.code || "",
									applet: applet,
									share_phyid:uni.getStorageSync("share_phyid"),
									source:'41',//41代表武警店
								},
							}).then((res) => {
								uni.hideLoading()
								// 存下缓存
								console.log('1登陆成功')
								that.huancun(res);
							})
						}
					});
					return false
					// #endif
					util.request({
						url: '/mobile/index.php?act=login&op=loginThreeWay',
						method: 'POST',
						data: {
							username: that.username,
							password: msdjs.hexMD5(that.userpass),
							vercode: that.userpass2,
							client: that.client,
							login_role: "1",
							loginType: loginType,
							wxcode: that.code || "",
							applet: applet,
							share_phyid:uni.getStorageSync("share_phyid")
						},

					}).then((res) => {
						uni.hideLoading()
						console.log('2登陆成功')
						// 存下缓存
						this.huancun(res);
					}).catch(err => {
						console.log('账号密码登录', err)
					})
				} else {
					uni.showToast({
						title: "手机号或者密码不能为空",
						icon: "none",
					})
				}

			},
			loginuni() { //APP微信登录
				if (!this.ifchenked) {
					uni.showToast({
						title: "请同意隐私协议",
						icon: "none"
					})
					return false
				}
				uni.showLoading({})
				var that = this;
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log('成功', loginRes)
						// 获取用户信息
						uni.getUserInfo({
							provider: 'weixin',
							success: (infoRes) => {
								console.log('用户信息：', infoRes.userInfo);
								that.avatarUrl = infoRes.userInfo.avatarUrl
								that.$util.request({
									url: '/mobile/index.php?act=login&op=app_wxoauth',
									method: 'post',
									data: {
										username: infoRes.userInfo.nickName,
										headimgurl: infoRes.userInfo.avatarUrl,
										openid: infoRes.userInfo.openId,
										unionid: infoRes.userInfo.unionId,
										type: 1,
										client: that.client,
									},
								}).then((res) => {
									uni.hideLoading()
									if (res.error_code != 0) {
										uni.showToast({
											title: res.message,
											icon: "none"
										})
										return false
									}
									if (res.datas.state == 1) {
										// 存下缓存
										that.huancun(res);
									} else {
										that.unionId = res.datas.wx_userinfo.unionid;
										uni.showModal({
											title: '提示',
											content: '是否注册新账号?',
											cancelText: "已有账号", //取消按钮文字
											confirmText: "新用户", //确认按钮文字
											success: function(res2) {
												if (res2.confirm) {
													if (res.datas
														.share_id
													) {
														that.invitation =
															res
															.datas
															.share_id;
													}
													that.titleText =
														true
													that.isbinding =
														true;
													that.ishide =
														true
												} else if (res2
													.cancel) {
													that.ishide =
														true
													that.titleText =
														false
													that.isbinding =
														true;
												}
											}
										});
									}
								})
							},
							fail(err) {
								console.log('失败2', err)
							}
						});
					},
					fail(err) {
						console.log('失败1', err)
					}
				});
			},
			loginqq() { //QQ登录
				if (!this.ifchenked) {
					uni.showToast({
						title: "请同意隐私协议",
						icon: "none"
					})
					return false
				}
				uni.showLoading({})
				var that = this;
				uni.login({
					provider: 'qq',
					success: function(loginRes) {
						// 获取用户信息
						uni.getUserInfo({
							provider: 'qq',
							success: function(infoRes) {
								console.log('用户昵称为：', loginRes);
								console.log('用户昵称为：', infoRes);
								that.nickname = infoRes.userInfo.nickName
								that.headimgurl = infoRes.userInfo.avatarUrl
								that.qqopenid = infoRes.userInfo.openId
								that.$util.request({
									url: '/mobile/index.php?act=login&op=qq_oauth',
									method: 'post',
									data: {
										username: infoRes.userInfo.nickName,
										headimgurl: infoRes.userInfo.avatarUrl,
										openid: infoRes.userInfo.openid,
										type: 1,
										client: that.client,
									},
								}).then((res) => {
									uni.hideLoading()
									if (res.error_code != 0) {
										uni.showToast({
											title: res.message,
											icon: "none"
										})
										return false
									}

									if (res.datas.state == 1) {
										// 存下缓存
										that.huancun(res);
									} else {
										uni.showModal({
											title: '提示',
											content: '是否注册新账号?',
											cancelText: "已有账号", //取消按钮文字
											confirmText: "新用户", //确认按钮文字
											success: function(res2) {
												if (res2.confirm) {
													if (res.datas
														.share_id
													) {
														that.invitation =
															res
															.datas
															.share_id;
													}
													that.types =
														"qq"
													that.titleText =
														true
													that.isbinding =
														true;
													that.ishide =
														true
												} else if (res2
													.cancel) {
													that.types =
														"qq"
													that.ishide =
														true
													that.titleText =
														false
													that.isbinding =
														true;
												}
											}
										});
										that.unionId = res.datas.wx_userinfo
											.unionId;
									}
								})

							}
						});
					}
				});
			},

			loginAlipay() { //APP支付宝登录
				if (!this.ifchenked) {
					uni.showToast({
						title: "请同意隐私协议",
						icon: "none"
					})
					return false
				}
				uni.showLoading({})
				let that = this
				AlipayAuth.login({
						appId: '2021003192652139', //你在支付宝平台申请的App ID
						scheme: 'alixpayhbilderhello' // 需要传到支付宝SDK的scheme,注意需要在manifest.json-->App其他常用配置-->UrlSchemes中配置Android和iOS的
					},
					(res) => {
						console.log('原生授权返回code', res.auth_code)
						//客户端成功获取授权临时票据（code）,向业务服务器发起登录请求。
						that.$util.request({
							url: '/mobile/index.php?act=login&op=alipy_auth',
							method: 'post',
							data: {
								code: res.auth_code
							},
						}).then(res => {
							uni.hideLoading()
							if (res.error_code != 0) {
								uni.showToast({
									title: res.message,
									icon: "none"
								})
								return false
							}
							if (res.datas.state == 1) {
								// 存下缓存
								that.huancun(res);
							} else {
								that.nickname = res.datas.wx_userinfo.nickname
								that.avatarUrl = res.datas.wx_userinfo.headimgurl
								that.headimgurl = res.datas.wx_userinfo.headimgurl
								that.types = 'alipay'
								that.openId = res.datas.wx_userinfo.openid;
								uni.showModal({
									title: '提示',
									content: '是否注册新账号?',
									cancelText: "已有账号", //取消按钮文字
									confirmText: "新用户", //确认按钮文字
									success: function(res2) {
										if (res2.confirm) {
											if (res.datas.share_id) {
												that.invitation = res.datas.share_id;
											}
											that.titleText = true
											that.isbinding = true;
											that.ishide = true
										} else if (res2.cancel) {
											that.ishide = true
											that.titleText = false
											that.isbinding = true;
										}
									},
									fail(err) {
										console.log('失败2', err)
									}
								});
							}
						})
					})

			},
			checkboxChangeifchen(e) {
				let that = this;
				that.ifchenked = !that.ifchenked
			},
			// 删除用户
			cloerUser() {
				let that = this;
				that.username = "";
				that.cloershow = false
			},
			isChenk() {
				this.isshowChenk = !this.isshowChenk
			},
			// 监听输入框
			usernameinput() {
				let that = this;
				if (that.username.length > 0) {
					that.cloershow = true
				} else {
					that.cloershow = false
				}
			},
			seeWord() {
				this.isSee = !this.isSee;
			},
			pagelogin() {
				uni.redirectTo({
					url: './codelogin'
				})
			},
			toforgetpwd() {
				uni.navigateTo({
					url: 'forget_password'
				});
			},
			huancun(res) { //登录成功回调
				console.log('登录成功的回调', res)
				let that = this
				if (res.error_code == 0) {
					uni.setStorageSync("key", res.datas.key);
					uni.setStorageSync("api_member_name", res.datas.username)
					uni.setStorageSync("api_member_id", res.datas.member_id)
					if (res.datas.openid) {
						uni.setStorageSync("openid", res.datas.openid)
					}
					uni.showToast({
						title: "登录成功",
						icon: "none",
						success: () => {
							setTimeout(() => {
								// #ifdef H5
								let ua = window.navigator.userAgent.toLowerCase();
								if (ua.match(/MicroMessenger/i) == 'micromessenger') {
									this.previous = uni.getStorageSync('previous')
									uni.removeStorageSync('previous');
									if (this.previous) {
										window.location.href = decodeURIComponent(this
											.previous)
										console.log(decodeURIComponent(this.previous),
											"decodeURIComponent(this.previous)")
									} else {
										window.location.href = this.$share +
											"/?#/main/home/index"
									}
									return false;
								}
								// #endif
								var pages = getCurrentPages(); //当前页
								let beforePage = (pages[pages.length - 2]); //上个页面、
								console.log(beforePage)
								if (beforePage) {
									uni.navigateBack();
									return
								}
								console.log('我要跳转')
								uni.switchTab({
									url: '/main/home/index'
								})
								// }
							}, 500)
						}
					})
				} else {
					if (res.message == 'token已失效，您已在其他客户端登录') {
						that.isToken = false
						uni.showToast({
							title: "该账号已在其他客户端登录",
							icon: "none"
						})
					} else {
						uni.showToast({
							title: res.message,
							icon: "none"
						})
					}

				}
			}
		}
	}
</script>
<style lang="scss">
	.automatic_logon {
		/deep/ uni-checkbox .uni-checkbox-input {
			border-radius: 50% !important;
			color: #ffffff !important;
			border-color: #707070;

		}

		/deep/ uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
			color: #fff;
			border-color: #FF4300;
			background: #FF4300;
		}

		/deep/ uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:after {
			font-size: 36rpx;
			border-color: #707070;
		}
	}

	.getnickbox {
		padding: 40rpx 20rpx;
		background-color: #FFFFFF;

		.logoimg {
			width: 50rpx;
			height: 50rpx;
		}

		.name {
			margin-left: 20rpx;

			text {
				margin-left: 10rpx;
			}
		}

		.m1 {
			font-weight: 500;
		}

		.m2 {
			padding-bottom: 30rpx;
			border-bottom: 1rpx solid #f2f2f2;
			color: #999;
			padding-top: 10rpx;
			font-size: 24rpx;
		}

		.xin1 {
			border-bottom: 1rpx solid #f2f2f2;
			margin-bottom: 30rpx;

			.toubox {
				padding: 10rpx 0;
				display: flex;
				align-items: center;

				.t1 {
					font-size: 28rpx;
					margin-right: 30rpx;
				}

				.avatarbox {
					width: 100rpx;
					height: 100rpx;
					border-radius: 20rpx;
				}

				.avatarimg {
					width: 100rpx;
					height: 100rpx;
					border-radius: 20rpx;
				}
			}
		}

		.right_arrow {
			width: 20rpx;
			height: 30rpx;
		}

		.buttoncss {
			background-color: #fff;
			border-radius: 0rpx;
			border: 0rpx solid transparent;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0rpx;
		}

		button::after {
			border: 0rpx solid rgba(0, 0, 0, .2);
		}

		.nick {
			padding-bottom: 30rpx;
			border-bottom: 2rpx solid #f2f2f2;
			display: flex;
			align-items: center;

			.n1 {
				font-size: 28rpx;
				margin-right: 30rpx;
			}
		}

		.wan {
			position: relative;
			height: 100rpx;
			box-shadow: 0rpx 0rpx 0rpx 0rpx;
			margin-top: 30rpx;

			.btn {
				background: #FF5722;
			}
		}

		.mt30 {
			margin-top: 30rpx;
		}
	}

	.flex_align_center {
		display: flex;
		align-items: center;
	}

	.logobox {
		width: 100%;
		height: 100vh;
		background: rgba(42, 31, 31, 0.5);
		backdrop-filter: blur(6rpx);
		position: fixed;
		left: 0;
		top: 0;
	}

	.logoboxtitle {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #3F3838;
		line-height: 44rpx;
		padding: 48rpx;
		width: 440rpx;
		text-align: center;
	}

	.register {
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #E26D2C;
		line-height: 82rpx;
		border: 2rpx solid #F5F3EC;
		background-color: #fff;
		height: 82rpx;
		text-align: center;
	}

	.logoboxcenter {
		background-color: #fff;
		position: fixed;
		left: 50%;
		top: 50%;
		border-radius: 16rpx;
		overflow: hidden;
		margin-left: -254rpx;
		margin-top: -150rpx;
	}
</style>
<style>
	.boright {
		border-right: 1rpx solid #EEEEEE;
	}

	.TipsBox {
		background-color: #FFFFFF;
		width: 600rpx;
		padding: 20rpx;
		border-radius: 20rpx;
		text-align: center;
	}

	.TipsBox .Title {
		font-size: 34rpx;
		font-weight: bold;
	}

	.TipsBox .content {
		margin: 30rpx 0;
	}

	uni-button:after {
		border: 0;
	}

	.TipsBox .BtnBox button,
	.TipsBox .BtnBox view {
		width: 50%;
		/* border: 0 !important; */
		border-top: 1rpx solid #EEEEEE;
		background-color: #FFFFFF;
		color: #333333;
	}

	.mag40 {
		margin: 40rpx 0;

	}

	.flexBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		flex-wrap: nowrap;
	}

	.flexBox input {
		width: 250rpx;
		/* border:1rpx solid #999; */
	}

	.flexBox .Phone {
		width: 400rpx;
	}



	.bgco {
		padding: inherit;
		width: 100%;
		height: 100vh;
		background: #FFFFFF;
		/* background: url(../../static/images/sengdie01.png) no-repeat; */
		/* margin-top: 130rpx; */
		box-sizing: 100%;
		position: fixed;
		top: 0;
	}



	.shadow {
		/* #ifdef MP-WEIXIN */
		background-color: rgba(51, 51, 51, 0.3);
		/* #endif */
	}

	.bgco .authorization {
		background-color: #ff4300;
		text-align: center;
		line-height: 70rpx;
		width: 400rpx;
		border-radius: 70rpx;
		margin: 0 auto;
		color: #FFFFFF;
		margin-top: 20rpx;
	}

	.bgco .ImgBox {
		margin: 0 auto;
		width: 140rpx;
		height: 140rpx;
		border: 4rpx solid #eee;
		border-radius: 50%;
		position: absolute;
		top: -75rpx;
		left: 0;
		right: 0;
		background-color: #FFF9FC;
	}

	.bgco .ImgBox image {
		width: 140rpx;
		height: 140rpx;
		border-radius: 50%;
	}

	.inputBox {
		border-bottom: 1rpx solid #eee;
		margin-bottom: 50rpx;
		height: 50rpx;
	}

	.bgco .Box {
		position: relative;
		margin: 380rpx auto;
		width: 600rpx;
		height: 560rpx;
		background-color: #FFFFFF;
		padding: 40rpx 20rpx;
		border-radius: 20rpx;
		color: #999999;
		text-align: center;
		padding-top: 80rpx;
		box-sizing: border-box;
	}

	.authorized {
		text-align: center;
	}

	.authorized-logo {
		width: 400rpx;
		height: 196rpx;
		margin-top: 300rpx;
	}

	.authorized-logoText {
		font-size: 30rpx;
		font-weight: bold;
		color: #FF4300;
		margin-bottom: 80rpx;
	}

	.authorized-btn {
		width: 650rpx;
		height: 90rpx;
		border-radius: 50rpx;
		font-size: 36rpx;
		font-weight: 400;
		color: #FFFFFF;
	}

	.authorized-wxbtn {
		background: #21D86D;
	}

	.authorized-zhbtn {
		margin-top: 40rpx;
		background: #FF4300;
	}

	.ZH-login {
		text-align: center;
	}

	.ZH-logo {
		width: 400rpx;
		height: 196rpx;
		margin-top: 82rpx;
		margin-bottom: 154rpx;
	}

	.switch {
		font-size: 24rpx;
		font-weight: 400;
		color: #909090;
		margin: 30rpx 50rpx 170rpx 50rpx;
		display: flex;
		justify-content: space-around;
	}

	.switch-register {
		font-size: 28rpx;
		padding: 0;
		margin: 0;
		line-height: 0;
	}

	.obtain_code {
		width: 120rpx;
		font-size: 24rpx;
		font-weight: 400;
		color: #FF4300;
		line-height: 0;
		background-color: #fff;
	}

	.nav_title_item {
		text-align: center;
	}

	navigator:hover {
		background-color: #F0F0F0;
	}

	uni-page-body {
		background-color: #FFFFFF;
		color: rgb(102, 102, 102);
	}

	.NavBar {
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999999;
		font-weight: bold;
	}

	.login_input {
		text-align: left;
		width: 500rpx;
		box-sizing: border-box;
		padding-left: 0;
		font-size: 28rpx !important;
		border: none;
		padding-right: 0;
		margin-left: 10rpx;
		outline: none;
	}

	.automatic_logon {
		width: 650rpx;
		padding: 0rpx 0rpx;
		margin: 30rpx 0 60rpx 0;
		box-sizing: border-box;
	}

	.automatic_logon_right {
		font-size: 26rpx;
		font-weight: 400;
		color: #909090;
		line-height: 0;
	}

	.ifchenkedactive {
		background: #ff4300;

	}

	.chenkeduser_box {
		margin-right: 10upx;
		height: 24upx;
		width: 24upx;
		border-width: 2rpx;
		border-color: rgb(229, 229, 229);
		border-style: solid;
		border-radius: 4rpx;
		background-color: rgb(238, 238, 238);
		position: relative;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.chenkeduser_box image {
		position: absolute;
		height: 14upx;
		width: 20upx;
		top: 5upx;
		left: 2upx;
		text-align: center;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.Content {
		background-color: #FFFFFF;
	}

	.previous {
		position: fixed;
		width: 50rpx;
		height: 50rpx;
		z-index: 999999999;
		border-radius: 50%;
		display: flex;
		align-items: center;
		top: 400rpx;
		right: 100rpx;

	}

	.previous image {
		width: 36rpx;
		height: 35rpx;
		margin: 0 auto;
	}

	.chenkeduser_box_pent {
		display: flex;
		align-items: center;

	}

	.ifchenkedactive {
		background-image: -moz-linear-gradient(172deg, #ff4300 0%, #ff4300 100%);
		background-image: -webkit-linear-gradient(172deg, #ff4300 0%, #ff4300 100%);
		background-image: -ms-linear-gradient(172deg, #ff4300 0%, #ff4300 100%);
	}

	uni-page-body {
		background-color: #FFFFFF;

		color: rgb(102, 102, 102);
	}

	.Agreement {
		color: #FF4300;
	}

	.forget_content {
		padding: 50upx 20upx;
		font-size: 28upx;
	}

	.register_top {
		padding: 70upx 130upx;
		font-weight: 700;
		font-size: 56rpx;
		font-family: "Microsoft YaHei";
		color: rgb(51, 51, 51);
	}

	.frameBox {
		width: 700rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 20rpx;
		box-sizing: border-box;
		margin: 0 auto;
	}
</style>